package com.yuke.cloud.common.base.constant;

import com.google.common.collect.Lists;
import com.yuke.cloud.common.base.enums.ErrorCodeEnum;
import com.yuke.cloud.common.base.exception.BusinessException;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

import static com.yuke.cloud.common.base.constant.GlobalConstant.ValidateTypeEnum.*;

/**
 * The class Aliyun sms constants.
 *
 * @author
 */
public class AliyunSmsConstants {

	/**
	 * 短信模板枚举
	 */
	public enum SmsTempletEnum {

		/**
		 * 身份验证模板(短信内容:验证码${code}，您正在进行身份验证，打死不要告诉别人哦！)
		 */
		UAC_SMS_IDENTITY_VER_TEMPLATE(IDENTITY_VER, "SMS_147715048", "code"),
		/**
		 * 登录确认模板(短信内容:验证码${code}，您正在登录，若非本人操作，请勿泄露。)
		 */
		UAC_SMS_LOGIN_CONFIRM_TEMPLATE(LOGIN_CONFIRM, "SMS_147715047", "code"),
		/**
		 * 登录异常模板(短信内容:验证码${code}，您正尝试异地登录，若非本人操作，请勿泄露。)
		 */
		UAC_SMS_LOGIN_EXCEPTION_TEMPLATE(LOGIN_EXCEPTION, "SMS_147715046", "code"),
		/**
		 * 用户注册模板(短信内容:验证码${code}，您正在注册成为新用户，感谢您的支持！)
		 */
		UAC_SMS_USER_REG_TEMPLATE(USER_REG, "SMS_147715045", "code"),
		/**
		 * 修改密码模板(短信内容:验证码${code}，您正在尝试修改登录密码，请妥善保管账户信息。)
		 */
		UAC_SMS_PASSWORD_MOD_TEMPLATE(PASSWORD_MOD, "SMS_147715044", "code"),
		/**
		 * 信息变更模板(短信内容:验证码${code}，您正在尝试变更重要信息，请妥善保管账户信息。)
		 */
		UAC_SMS_INFO_MOD_TEMPLATE(INFO_MOD, "SMS_147715043", "code"),

		/**
		 * 用户找回密码(短信内容:尊敬的用户，您的注册用户密码为：${code}，请勿泄漏于他人！为防止密码泄漏，请登录后立即修改密码！)
		 */
		UAC_SMS_PASSWORD_GETBACK(PASSWORD_GETBACK, "SMS_152212040", "code");

		private GlobalConstant.ValidateTypeEnum busType;

		private String templetCode;

		private String smsParamName;

		public static SmsTempletEnum getEnum(String templateCode) {
			SmsTempletEnum smsTempletEnum = null;
			for (SmsTempletEnum ele : SmsTempletEnum.values()) {
				if (templateCode.equals(ele.getTempletCode())) {
					smsTempletEnum = ele;
					break;
				}
			}
			return smsTempletEnum;
		}

		public static SmsTempletEnum getEnum(GlobalConstant.ValidateTypeEnum busType) {
			SmsTempletEnum smsTempletEnum = null;
			for (SmsTempletEnum ele : SmsTempletEnum.values()) {
				if (busType.getCode() == ele.busType.getCode()) {
					smsTempletEnum = ele;
					break;
				}
			}
			return smsTempletEnum;
		}

		public static boolean isSmsTemplate(String smsTemplateCode) {

			if (StringUtils.isEmpty(smsTemplateCode)) {
				throw new BusinessException(ErrorCodeEnum.UAC10011020);
			}
			List<String> templetCodeList = getTemplateCodeList();

			return templetCodeList.contains(smsTemplateCode);
		}

		public static List<SmsTempletEnum> getList() {
			return Arrays.asList(SmsTempletEnum.values());
		}

		public static List<String> getTemplateCodeList() {
			List<String> templetCodeList = Lists.newArrayList();
			List<SmsTempletEnum> list = getList();
			for (SmsTempletEnum templetEnum : list) {
				if (StringUtils.isEmpty(templetEnum.getTempletCode())) {
					continue;
				}
				templetCodeList.add(templetEnum.getTempletCode());
			}
			return templetCodeList;
		}

		SmsTempletEnum(GlobalConstant.ValidateTypeEnum busType, String templetCode, String smsParamName) {
			this.busType = busType;
			this.templetCode = templetCode;
			this.smsParamName = smsParamName;
		}

		/**
		 * Gets bus type.
		 *
		 * @return the bus type
		 */
		public GlobalConstant.ValidateTypeEnum getBusType() {
			return busType;
		}

		/**
		 * Gets templet code.
		 *
		 * @return the templet code
		 */
		public String getTempletCode() {
			return templetCode;
		}

		/**
		 * Gets sms param name.
		 *
		 * @return the sms param name
		 */
		public String getSmsParamName() {
			return smsParamName;
		}
	}


}
